package com.ruoyi.members.service.impl;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.enums.UnionsStatus;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.members.mapper.SysGrassrootsTradeUnionsMapper;
import com.ruoyi.members.domain.SysGrassrootsTradeUnions;
import com.ruoyi.members.service.ISysGrassrootsTradeUnionsService;

/**
 * 基层工会Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@Service
public class SysGrassrootsTradeUnionsServiceImpl extends ServiceImpl<SysGrassrootsTradeUnionsMapper, SysGrassrootsTradeUnions> implements ISysGrassrootsTradeUnionsService
{
    @Autowired
    private SysGrassrootsTradeUnionsMapper sysGrassrootsTradeUnionsMapper;

    @Autowired
    private ISysGrassrootsTradeUnionsService sysGrassrootsTradeUnionsService;

    /**
     * 查询基层工会
     * 
     * @param unionsId 基层工会主键
     * @return 基层工会
     */
    @Override
    public SysGrassrootsTradeUnions selectSysGrassrootsTradeUnionsByUnionsId(Long unionsId)
    {
        return sysGrassrootsTradeUnionsMapper.selectSysGrassrootsTradeUnionsByUnionsId(unionsId);
    }

    /**
     * 查询基层工会列表
     * 
     * @param sysGrassrootsTradeUnions 基层工会
     * @return 基层工会
     */
    @Override
    public List<SysGrassrootsTradeUnions> selectSysGrassrootsTradeUnionsList(SysGrassrootsTradeUnions sysGrassrootsTradeUnions)
    {
        return sysGrassrootsTradeUnionsMapper.selectSysGrassrootsTradeUnionsList(sysGrassrootsTradeUnions);
    }

    /**
     * 新增基层工会
     * 
     * @param sysGrassrootsTradeUnions 基层工会
     * @return 结果
     */
    @Override
    public int insertSysGrassrootsTradeUnions(SysGrassrootsTradeUnions sysGrassrootsTradeUnions)
    {
        sysGrassrootsTradeUnions.setCreateTime(DateUtils.getNowDate());
        return sysGrassrootsTradeUnionsMapper.insertSysGrassrootsTradeUnions(sysGrassrootsTradeUnions);
    }

    /**
     * 修改基层工会
     * 
     * @param sysGrassrootsTradeUnions 基层工会
     * @return 结果
     */
    @Override
    public int updateSysGrassrootsTradeUnions(SysGrassrootsTradeUnions sysGrassrootsTradeUnions)
    {
        sysGrassrootsTradeUnions.setUpdateTime(DateUtils.getNowDate());
        return sysGrassrootsTradeUnionsMapper.updateSysGrassrootsTradeUnions(sysGrassrootsTradeUnions);
    }

    /**
     * 批量删除基层工会
     * 
     * @param unionsIds 需要删除的基层工会主键
     * @return 结果
     */
    @Override
    public int deleteSysGrassrootsTradeUnionsByUnionsIds(Long[] unionsIds)
    {
        return sysGrassrootsTradeUnionsMapper.deleteSysGrassrootsTradeUnionsByUnionsIds(unionsIds);
    }

    /**
     * 删除基层工会信息
     * 
     * @param unionsId 基层工会主键
     * @return 结果
     */
    @Override
    public int deleteSysGrassrootsTradeUnionsByUnionsId(Long unionsId)
    {
        return sysGrassrootsTradeUnionsMapper.deleteSysGrassrootsTradeUnionsByUnionsId(unionsId);
    }

    /**
     * 批量删除基层工会信息
     * @param unionsIds
     * @return
     */
    @Override
    public UnionsStatus deleteSysGrassrootsTradeUnionsByIds(Long[] unionsIds) {
        //判断基层工会是否存在
        List<SysGrassrootsTradeUnions> list = listByIds(Arrays.asList(unionsIds));
        if (list.isEmpty()){
            return UnionsStatus.UNIONS_NOT_EXIST;
        }
        sysGrassrootsTradeUnionsService.removeByIds(Arrays.asList(unionsIds));
        return UnionsStatus.SUCCESS;
    }
}
